package com.fzu.ess.ess.controller;

import com.fzu.ess.common.Model.JsonModel;
import com.fzu.ess.ess.entity.Profile;
import com.fzu.ess.ess.service.ProfileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by ercha on 2015/10/25.
 */

@Controller
@RequestMapping(value = "/profile")
public class ProfileController{
    @Autowired
    private ProfileService profileService;

    @RequestMapping(value = "/update", method = RequestMethod.GET)
    public String updatePage(Model model) {
        model.addAttribute("profile", profileService.get());
        return "/jsp/common/profile/update.jsp";
    }

    @ResponseBody
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JsonModel update(Profile profile){
//        System.out.println("here create Profile");
        JsonModel jsonModel = new JsonModel();
        try {
            jsonModel.setSuccess(profileService.update(profile));
        } catch(Exception e){
            e.printStackTrace();
        }

        return jsonModel;
    }
}
